/**
 *   Copyright 2008 Alexey Vishentsev
 *
 *   Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 */

package com.gwtspreadsheetinput.jsf.component;

import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentELTag;

public class SpreadSheetTag extends UIComponentELTag {
	
	private javax.el.ValueExpression value;
	private String var;
	private String rowObjectClassName;
	private String width;
	private String height;
	private String jsFolder;
	private int selectionRow = -1;
	private int selectionCol = -1;

	public String getComponentType() {
		return "com.gwtspreadsheetinput.jsf.SpreadSheet";
	}

	public String getRendererType() {
		return "com.gwtspreadsheetinput.jsf.SpreadSheetRenderer";
	}
	
	public void setValue(ValueExpression value) {
		this.value = value;
	}
	
	public void setVar(String var) {
		this.var = var;
	}
	
	public void setJsFolder(String jsFolder) {
		this.jsFolder = jsFolder;
	}
	
	public void setWidth(String width) {
		this.width = width;
	}
	
	public void setHeight(String height) {
		this.height = height;
	}
	
	public int getSelectionRow() {
		return selectionRow;
	}

	public void setSelectionRow(int selectionRow) {
		this.selectionRow = selectionRow;
	}

	public int getSelectionCol() {
		return selectionCol;
	}

	public void setSelectionCol(int selectionCol) {
		this.selectionCol = selectionCol;
	}

	public String getRowObjectClassName() {
		return rowObjectClassName;
	}

	public void setRowObjectClassName(String rowObjectClassName) {
		this.rowObjectClassName = rowObjectClassName;
	}

	protected void setProperties(UIComponent component) {
		super.setProperties(component);
		try {
			SpreadSheet spreadSheet = (SpreadSheet) component;
			if (value != null) {
				spreadSheet.setValueExpression("value", value);
			}
			spreadSheet.setVar(var);
			spreadSheet.setJsFolder(jsFolder);
			spreadSheet.setHeight(height);
			spreadSheet.setWidth(width);
			spreadSheet.setSelectionRow(selectionRow);
			spreadSheet.setSelectionCol(selectionCol);
			spreadSheet.setRowObjectClassName(rowObjectClassName);
		} catch (ClassCastException e) {
			throw new IllegalArgumentException("Component " + component + 
					"is not of type com.gwtspreadsheetinput.jsf.SpreadSheet");
			
		}
	}
	
	public void release() {
		super.release();
		value = null;
		var = null;
		jsFolder = null;
		selectionRow = -1;
		selectionCol = -1;
	}
}
